<template>
  <Panel>
    <template>
      <!-- 表格 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="expand">
          <template v-slot="{ row }">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="商品ID">
                <span>{{ row.id }}</span>
              </el-form-item>
              <el-form-item label="所属分类">
                <span>{{ row.category }}</span>
              </el-form-item>
              <el-form-item label="商品价格">
                <span>{{ row.price }}</span>
              </el-form-item>
              <el-form-item label="创建时间">
                <span>{{ row.ctime | formName }}</span>
              </el-form-item>
              <el-form-item label="商品评价">
                <span>{{ row.rating }}</span>
              </el-form-item>
              <el-form-item label="商品销量">
                <span>{{ row.sellCount }}</span>
              </el-form-item>
              <el-form-item label="商品描述">
                <span>{{ row.goodsDesc }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="商品名称" prop="name"> </el-table-column>
        <el-table-column label="所属分类" prop="category"> </el-table-column>
        <el-table-column label="商品价格" prop="price"> </el-table-column>
        <el-table-column label="商品图片">
          <template v-slot="{ row }">
            <img :src="base + row.imgUrl" alt="" />
          </template>
        </el-table-column>
        <el-table-column label="商品描述" prop="goodsDesc"> </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button size="mini" type="primary">编辑</el-button>
            <el-button size="mini" type="danger">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[2, 5, 10, 15]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </template>
  </Panel>
</template>

<script>
// 引入商品列表接口
import { liSt } from '../../api/good.js'
export default {
  data() {
    return {
      tableData: [
        {
          id: '12987122',
          name: '好滋好味鸡蛋仔',
          category: '江浙小吃、小吃零食',
          desc: '荷兰优质淡奶，奶香浓而不腻',
          address: '上海市普陀区真北路',
          shop: '王小虎夫妻店',
          shopId: '10333'
        }
      ],
      currentPage: 1,
      pageSize: 4,
      total: 0,
      base: 'http://127.0.0.1:5000/upload/imgs/goods_img/'
    }
  },
  created() {
    this.getUsers()
  },

  methods: {
    async getUsers() {
      /* 发请求 */
      const { data, total } = await liSt({
        currentPage: this.currentPage,
        pageSize: this.pageSize
      })
      // console.log(data)
      // 成功之后的赋值
      this.tableData = data
      this.total = total
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.getUsers()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      this.currentPage = val
      this.getUsers()
    }
  }
}
</script>

<style lang="less" scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
img {
  width: 140px;
  height: 140px;
}
</style>
